﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using CloudShot.Entities;
using CloudShot.Utils;

namespace CloudShot.Services
{
  public class HotkeyActionService
  {
    private readonly List<LongActionInfo> _longActionKeys = new List<LongActionInfo>();

    public bool RegisterAction(Hotkey hotkey, Action callback, int tickInterval)
    {
      var action = new LongActionInfo
      {
        Hotkey = hotkey,
        Callback = callback,
        TickInterval = tickInterval
      };

      _longActionKeys.Add(action);
      return true;
    }

    public bool OnKeyDown(Keys keys)
    {
      bool isKeyProcessed = false;

      Hotkey hotkey = keys.BuildFullHotkey();
      //Debug.WriteLine(keys);
      foreach (var longActionInfo in _longActionKeys.Where(i => i.Hotkey == hotkey))
      {
        longActionInfo.OnKeyDown();
        isKeyProcessed = true;
      }

      return isKeyProcessed;
    }
  }
}